chrome.storage.sync.get(['doc360'], function(result) {
    console.log('360doc.js: Value currently is ' + result.doc360);
    if (result.doc360) doc360Simple();
});

///////////entry//////////////////
function doc360Simple() {

if (!document.URL.includes("360doc.com")) {
    return;
}

let runInPageContext = function (fn) {
    var script = document.createElement('script');
    script.textContent = '(' + fn + ')();';
    document.body.appendChild(script);
};

runInPageContext(() => {
    let contextmenudiv = document.getElementById("contextmenudiv");
    if (!contextmenudiv) {
        return;
    }
    let printmenu = contextmenudiv.firstElementChild.children[1].firstChild;
    //printmenu.setAttribute("onclick","PrintObj.print()");
    printmenu.setAttribute("onclick", "if($('body').hasClass('fullopen')) {$('#artfullscreen_closer').trigger('click')};setTimeout(()=>PrintObj.print(),1000)");
});

setTimeout(() => {
    let fullbtn = document.getElementsByClassName("newbtn_fullscreen");
    if (fullbtn[0]) {
        fullbtn[0].setAttribute("onclick", "setTimeOut(()=>{document.body.lastChild.style.display='none'},200)");
    }

    let newbtn_word = document.getElementById("newbtn_word");
    if (newbtn_word) {
        newbtn_word.style.display="inherit";
        newbtn_word.setAttribute("onclick", "createArtIframe(2)");
    }
 
    let newbtn_print = document.getElementById("up_newbtn_print");
    if (newbtn_print) {
        newbtn_print.style.display="inherit";
        newbtn_print.setAttribute("onclick", "PrintObj.print()");
    }
}, 2000)


chrome.storage.sync.get(['i_doc360'], function(result) {
    console.log('360doc.js: auto is ' + result.i_doc360);
    if (result.i_doc360) {
        runInPageContext(() => {
            if (articlefullscreen) articlefullscreen(1);
        });
    }
});

}